using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using Framework;

namespace SchemaMonitor
{
    [Serializable()]
    public partial class CPublishSection : CBaseDynamic, IComparable<CPublishSection>
    {
        #region Constructors
        //Public (Copy Constructor)
        public CPublishSection(CPublishSection original, CDataSrc target)
        {
            //Database Connection
            m_dataSrc = target;

            //Copy fields
            _pubSecPublishId = original.PubSecPublishId;
            _pubSecSectionId = original.PubSecSectionId;
            _pubSecPostId = original.PubSecPostId;
            _pubSecText = original.PubSecText;
        }

        //Protected (Datareader/Dataset)
        protected CPublishSection(CDataSrc dataSrc, IDataReader dr) : base(dataSrc, dr) {}
        protected CPublishSection(CDataSrc dataSrc, DataRow     dr) : base(dataSrc, dr) {}
        #endregion

        #region Default Values
        protected override void InitValues_Auto()
        {
            //Null-Equivalent values (except String.Empty, as nulls tend to be inconvenient for string types)
            _pubSecId = int.MinValue;
            _pubSecPublishId = int.MinValue;
            _pubSecSectionId = int.MinValue;
            _pubSecPostId = long.MinValue;
            _pubSecText = string.Empty;
        }
        #endregion

        #region Members
        protected int _pubSecId;
        protected int _pubSecPublishId;
        protected int _pubSecSectionId;
        protected long _pubSecPostId;
        protected string _pubSecText;
        #endregion

        #region Properties - Column Values
        //Primary Key Column (ReadOnly)
        public int PubSecId    {   get { return _pubSecId;   } }

        //Table Columns (Read/Write)
        public int PubSecPublishId    {   get { return _pubSecPublishId; } set { _pubSecPublishId = value; }    }
        public int PubSecSectionId    {   get { return _pubSecSectionId; } set { _pubSecSectionId = value; }    }
        public long PubSecPostId    {   get { return _pubSecPostId; } set { _pubSecPostId = value; }    }
        public string PubSecText    {   get { return _pubSecText; } set { _pubSecText = value; }    }

        //View Columns (ReadOnly)

        #endregion

        #region MustOverride Methods
        //Schema Information
        public const string TABLE_NAME      = "PublishSections";
        public const string VIEW_NAME       = "";         //Used to override this.ViewName { get }
        public const string ORDER_BY_COLS   = "PubSecId";   //See the CompareTo method below (Sql-based sorting should match In-Memory sorting)
        public const string SORTING_COLUMN  = "";
        public override string TableName {    get { return TABLE_NAME; } }
        protected override string OrderByColumns {    get { return ORDER_BY_COLS; } }

        //CompareTo Interface (Default Sort Order)
        public int CompareTo(CPublishSection other) {   return this.PubSecId.CompareTo(other.PubSecId) ;  }

        //Primary Key Information
        public const string PRIMARY_KEY_NAME = "PubSecId";
        protected override bool InsertPrimaryKey {  get { return false;    }   }
        protected override string PrimaryKeyName {  get { return PRIMARY_KEY_NAME;    }    }
        protected override object PrimaryKeyValue 
        {
              get { return _pubSecId; }
              set { _pubSecId = (int)value; }
        }

        //Factory Methods - Object
        protected override CBase MakeFrom(DataRow row)      {   return new CPublishSection(this.DataSrc, row);  }
        protected override CBase MakeFrom(IDataReader dr)   {   return new CPublishSection(this.DataSrc, dr);   }

        //Factory Methods - List
        protected override IList MakeList()                 {   return new CPublishSectionList();               }
        protected override IList MakeList(int capacity)     {   return new CPublishSectionList(capacity);       }

        //Convert from ADO to .Net
        protected override void ReadColumns(IDataReader dr)
        {
            _pubSecId = CAdoData.GetInt(dr, "PubSecId");
            _pubSecPublishId = CAdoData.GetInt(dr, "PubSecPublishId");
            _pubSecSectionId = CAdoData.GetInt(dr, "PubSecSectionId");
            _pubSecPostId = CAdoData.GetLong(dr, "PubSecPostId");
            _pubSecText = CAdoData.GetStr(dr, "PubSecText");
        }
        protected override void ReadColumns(DataRow dr)
        {
            _pubSecId = CAdoData.GetInt(dr, "PubSecId");
            _pubSecPublishId = CAdoData.GetInt(dr, "PubSecPublishId");
            _pubSecSectionId = CAdoData.GetInt(dr, "PubSecSectionId");
            _pubSecPostId = CAdoData.GetLong(dr, "PubSecPostId");
            _pubSecText = CAdoData.GetStr(dr, "PubSecText");
        }

        //Parameters for Insert/Update    
        protected override CNameValueList ColumnNameValues()
        {
            CNameValueList data = new CNameValueList();
            data.Add("PubSecId", CAdoData.NullVal(_pubSecId));
            data.Add("PubSecPublishId", CAdoData.NullVal(_pubSecPublishId));
            data.Add("PubSecSectionId", CAdoData.NullVal(_pubSecSectionId));
            data.Add("PubSecPostId", CAdoData.NullVal(_pubSecPostId));
            data.Add("PubSecText", CAdoData.NullVal(_pubSecText));
            return data;
        }
        #endregion

        #region Queries - SelectAll/SelectWhere (inherited methods, cast only)
        //Select Queries - Non-Paged
        public new CPublishSectionList SelectAll()                                                          {    return (CPublishSectionList)base.SelectAll();                              }
        public new CPublishSectionList SelectAll(string orderBy)                                            {    return (CPublishSectionList)base.SelectAll(orderBy);                       }
        public new CPublishSectionList SelectWhere(string colName, ESign sign, object colValue)             {    return (CPublishSectionList)base.SelectWhere(colName, sign, colValue);     }
        public new CPublishSectionList SelectWhere(CCriteria where)                                         {    return (CPublishSectionList)base.SelectWhere(where);                       }
        public new CPublishSectionList SelectWhere(CCriteriaList where)                                     {    return (CPublishSectionList)base.SelectWhere(where);                       }
        public new CPublishSectionList SelectWhere(CCriteriaList where, string tableOrJoin)                 {    return (CPublishSectionList)base.SelectWhere(where, tableOrJoin);          }
        public new CPublishSectionList SelectWhere(CCriteriaList where, string tableOrJoin, string orderBy) {    return (CPublishSectionList)base.SelectWhere(where, tableOrJoin, orderBy); }
        [Obsolete("Arbitrary where-clause is not necessary portable or safe from sql injection attacks. Consider using the parameterised query interfaces")]
        public new CPublishSectionList SelectWhere(string unsafeWhereClause)                                {    return (CPublishSectionList)base.SelectWhere(unsafeWhereClause);           }
        public     CPublishSectionList SelectById(int pubSecId)                              {    return (CPublishSectionList)base.SelectById(pubSecId);       }
        public     CPublishSectionList SelectByIds(List<int> ids)                        {    return (CPublishSectionList)base.SelectByIds(ids);                         }

        //Select Queries - Paged
        public new CPublishSectionList SelectAll(  CPagingInfo pi)                                              {    return (CPublishSectionList)base.SelectAll(  pi);                              }
        public new CPublishSectionList SelectWhere(CPagingInfo pi, string name, ESign sign, object value)       {    return (CPublishSectionList)base.SelectWhere(pi, name, sign, value);           }
        public new CPublishSectionList SelectWhere(CPagingInfo pi, CCriteria criteria)                          {    return (CPublishSectionList)base.SelectWhere(pi, criteria);                    }
        public new CPublishSectionList SelectWhere(CPagingInfo pi, CCriteriaList criteria)                      {    return (CPublishSectionList)base.SelectWhere(pi, criteria);                    }
        public new CPublishSectionList SelectWhere(CPagingInfo pi, CCriteriaList criteria, string viewOrJoin)   {    return (CPublishSectionList)base.SelectWhere(pi, criteria, viewOrJoin);        }
        public     CPublishSectionList SelectByIds(CPagingInfo pi, List<int> ids)            {    return (CPublishSectionList)base.SelectByIds(pi, ids);                         }

        //Select Queries - Transactional
        public new CPublishSectionList SelectAll(                                                                                           IDbTransaction tx)  {    return (CPublishSectionList)base.SelectAll(tx);                                                     }
        public new CPublishSectionList SelectAll(string orderBy,                                                                            IDbTransaction tx)  {    return (CPublishSectionList)base.SelectAll(orderBy,                                         tx);    }
        public new CPublishSectionList SelectWhere(string columnName,               object columnValue,                                     IDbTransaction tx)  {    return (CPublishSectionList)base.SelectWhere(columnName,              columnValue,          tx);    }
        public new CPublishSectionList SelectWhere(string columnName,   ESign sign, object columnValue,                                     IDbTransaction tx)  {    return (CPublishSectionList)base.SelectWhere(columnName,    sign,     columnValue,          tx);    }
        public new CPublishSectionList SelectWhere(                             CCriteria     criteria,                                     IDbTransaction tx)  {    return (CPublishSectionList)base.SelectWhere(               criteria,                       tx);    }
        public new CPublishSectionList SelectWhere(                             CCriteriaList criteria,                                     IDbTransaction tx)  {    return (CPublishSectionList)base.SelectWhere(               criteria,                       tx);    }
        public new CPublishSectionList SelectWhere(                             CCriteriaList criteria, string tableOrJoin,                 IDbTransaction tx)  {    return (CPublishSectionList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public new CPublishSectionList SelectWhere(                             CCriteriaList criteria, string tableOrJoin, string orderBy, IDbTransaction tx)  {    return (CPublishSectionList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public     CPublishSectionList SelectById(int pubSecId,                                                              IDbTransaction tx)  {    return (CPublishSectionList)base.SelectById(pubSecId,                         tx);    }
        public     CPublishSectionList SelectByIds(List<int> ids,                                                        IDbTransaction tx)  {    return (CPublishSectionList)base.SelectByIds(ids,                                           tx);    }

        //Select Queries - Stored Procs
        public new CPublishSectionList MakeList(string storedProcName,                             IDbTransaction txOrNull)    {   return (CPublishSectionList)base.MakeList(storedProcName,             txOrNull);  }
        public new CPublishSectionList MakeList(string storedProcName, object[] parameters,        IDbTransaction txOrNull)    {   return (CPublishSectionList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishSectionList MakeList(string storedProcName, CNameValueList parameters,  IDbTransaction txOrNull)    {   return (CPublishSectionList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishSectionList MakeList(string storedProcName, List<object> parameters,    IDbTransaction txOrNull)    {   return (CPublishSectionList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishSectionList MakeList(string storedProcName, int param1,                 IDbTransaction txOrNull)    {   return (CPublishSectionList)base.MakeList(storedProcName, param1,     txOrNull);  }
        public new CPublishSectionList MakeList(string storedProcName, string param1,              IDbTransaction txOrNull)    {   return (CPublishSectionList)base.MakeList(storedProcName, param1,     txOrNull);  }

        //Query Results
        protected new CPublishSectionList MakeList(DataSet              ds) { return (CPublishSectionList)base.MakeList(ds);        }
        protected new CPublishSectionList MakeList(DataTable            dt) { return (CPublishSectionList)base.MakeList(dt);        }
        protected new CPublishSectionList MakeList(DataRowCollection  rows) { return (CPublishSectionList)base.MakeList(rows);      }
        protected new CPublishSectionList MakeList(IDataReader          dr) { return (CPublishSectionList)base.MakeList(dr);        }
        protected new CPublishSectionList MakeList(object           drOrDs) { return (CPublishSectionList)base.MakeList(drOrDs);    }        
        protected new CPublishSectionList MakeList(byte[]             gzip) { return (CPublishSectionList)base.MakeList(gzip);      }
        #endregion

        #region Queries - SelectBy[FK] (user-nominated fk/bool columns)
        //Non-Paged
        public CPublishSectionList SelectByPublishId(int pubSecPublishId)    {    return SelectWhere(new CCriteriaList("PubSecPublishId", pubSecPublishId));    }
        public CPublishSectionList SelectBySectionId(int pubSecSectionId)    {    return SelectWhere(new CCriteriaList("PubSecSectionId", pubSecSectionId));    }
        public CPublishSectionList SelectByPostId(long pubSecPostId)    {    return SelectWhere(new CCriteriaList("PubSecPostId", pubSecPostId));    }

        //Paged
        public CPublishSectionList SelectByPublishId(CPagingInfo pi, int pubSecPublishId)    {    return SelectWhere(pi, new CCriteriaList("PubSecPublishId", pubSecPublishId));    }
        public CPublishSectionList SelectBySectionId(CPagingInfo pi, int pubSecSectionId)    {    return SelectWhere(pi, new CCriteriaList("PubSecSectionId", pubSecSectionId));    }
        public CPublishSectionList SelectByPostId(CPagingInfo pi, long pubSecPostId)    {    return SelectWhere(pi, new CCriteriaList("PubSecPostId", pubSecPostId));    }

        //Count
        public int SelectCountByPublishId(int pubSecPublishId)   {   return SelectCount(new CCriteriaList("PubSecPublishId", pubSecPublishId));     }
        public int SelectCountBySectionId(int pubSecSectionId)   {   return SelectCount(new CCriteriaList("PubSecSectionId", pubSecSectionId));     }
        public int SelectCountByPostId(long pubSecPostId)   {   return SelectCount(new CCriteriaList("PubSecPostId", pubSecPostId));     }

        //Transactional
        public CPublishSectionList SelectByPublishId(int pubSecPublishId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubSecPublishId", pubSecPublishId), tx);    }
        public CPublishSectionList SelectBySectionId(int pubSecSectionId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubSecSectionId", pubSecSectionId), tx);    }
        public CPublishSectionList SelectByPostId(long pubSecPostId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubSecPostId", pubSecPostId), tx);    }
        #endregion

        #region ToXml
        protected override void ToXml_Autogenerated(System.Xml.XmlWriter w)
        {
            Store(w, "PubSecId", this.PubSecId);
            Store(w, "PubSecPublishId", this.PubSecPublishId);
            Store(w, "PubSecSectionId", this.PubSecSectionId);
            Store(w, "PubSecPostId", this.PubSecPostId);
            Store(w, "PubSecText", this.PubSecText);
        }
        #endregion

    }
}
